﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace 图书管理系统.Utils
{
    internal class SQLTool
    {
        #region 数据库参数
        private static string connString = "Data Source=(local);Initial Catalog=FaceSQL;Integrated Security=TRUE";
        private static SqlConnection con;
        #endregion

        #region 获取数据库连接
        public static SqlConnection GetCon()
        {
            con = new SqlConnection();
            con.ConnectionString = connString;
            return con;
        }
        #endregion

        #region 关闭数据库连接
        public static bool CloseSql()
        {
            try
            {
                if (con != null)
                {
                    con.Close();
                    if (con.State == ConnectionState.Closed)
                    {
                        return true;
                        //MessageBox.Show("Closed SQLserver Successfully");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Close failed, " + ex.Message);
            }
            return false;
        }
        #endregion
    }
}